/* ===========================================================================
 *
 *       Filename:  inputmethod_manager.cpp
 *
 *    Description:  inputmethod_manager, abstract, qt
 *
 * - Mode: 644
 * - NOTE. NOT use "dos"
 * - Updated: 2015-04-26 16:49:13
 *
 *        Version:  1.0.0
 *        Created:  2015-04-16 10:13:08
 *       Revision:  1.0.0
 *       Compiler:  g++
 *
 *         Author:  Yui Wong, email: yuiwong@126.com
 *   Organization:  ""
 *        License:  LGPLv3
 *
 *  This file is part of zinnia-handwriting.
 *
 *  zinnia-handwriting
 *  is free software: you can redistribute it
 *  and/or modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  zinnia-handwriting
 *  is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with zinnia-handwriting.
 *  If not, see <http://www.gnu.org/licenses/>.
 *
 * ===========================================================================
 */


#include <inputmethod_manager.h> /* class inputmethod_manager */
#include <inputmethod.h>

#if defined(PIMETHOD_DEBUG)
#	include <QtCore/QDebug>
#endif

/*
 * ===========================================================================
 * class inputmethod_manager
 * ===========================================================================
 */
inputmethod * inputmethod_manager::_method = NULL;
bool inputmethod_manager::method_no_bond = false;


inputmethod_manager::inputmethod_manager (void) {
#	if defined(PIMETHOD_DEBUG)
	qDebug() << __FILE__ << __LINE__ << __func__;
#	endif /* if defined(PIMETHOD_DEBUG) */

	inputmethod_manager::_method = NULL;
} /* inputmethod_manager::inputmethod_manager */


inputmethod_manager::~inputmethod_manager (void) {
#	if defined(PIMETHOD_DEBUG)
	qDebug() << __FILE__ << __LINE__ << __func__;
#	endif /* if defined(PIMETHOD_DEBUG) */

	this->method_release(inputmethod_manager::method_no_bond);
} /* inputmethod_manager::~inputmethod_manager */


void inputmethod_manager::method_release (bool method_no_bond) {
#	if defined(PIMETHOD_DEBUG)
	qDebug() << __FILE__ << __LINE__ << __func__;
#	endif /* if defined(PIMETHOD_DEBUG) */

	inputmethod_manager::method_no_bond = method_no_bond;

	if (method_no_bond && inputmethod_manager::_method) {
		delete inputmethod_manager::_method;
		inputmethod_manager::method_released();
	}
} /* inputmethod_manager::method_no_bond */


void inputmethod_manager::method_released (void) {
#	if defined(PIMETHOD_DEBUG)
	qDebug() << __FILE__ << __LINE__ << __func__;
#	endif /* if defined(PIMETHOD_DEBUG) */

	inputmethod_manager::_method = NULL;
} /* inputmethod_manager::method_released */


inputmethod * inputmethod_manager::method (QWidget * focus,
	const char * conf, QWidget * parent4method) {
#	if defined(PIMETHOD_DEBUG)
	qDebug() << __FILE__ << __LINE__ << __func__;
#	endif /* if defined(PIMETHOD_DEBUG) */

	if (NULL == this->_method) {
		this->_method = this->create_method(focus, conf, parent4method);
	}

	return this->_method;
} /* inputmethod_manager::method */
/*
 * ===========================================================================
 * end of class inputmethod_manager
 * ===========================================================================
 */
/*
 * end of file inputmethod_manager.cpp
 */
